home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / ifgate / batchrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-04  |  1.3 KB  |  67 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "lutil.h"
  4.  
  5. static long counter = 0L;
  6. static int batchmode = -1;
  7. extern int usetmp;
  8.  
  9. char *bgets(buf,count,fp)
  10. char *buf;
  11. int count;
  12. FILE *fp;
  13. {
  14.     if (usetmp)
  15.     {
  16.         return fgets(buf,count,fp);
  17.     }
  18.  
  19.     if ((batchmode == 1) && (counter > 0L) && (counter < (long)(count-1))) 
  20.         count=(int)(counter+1L);
  21.     if (fgets(buf,count,fp) == NULL) return NULL;
  22.     switch (batchmode)
  23.     {
  24.     case -1: if (!strncmp(buf,"#! rnews ",9) || !strncmp(buf,"#!rnews ",8))
  25.         {
  26.             batchmode=1;
  27.             sscanf(buf+8,"%ld",&counter);
  28.             debug(18,"first chunk of input batch: %ld",counter);
  29.             if (counter < (long)(count-1)) count=(int)(counter+1L);
  30.             if (fgets(buf,count,fp) == NULL) return NULL;
  31.             else
  32.             {
  33.                 counter -= strlen(buf);
  34.                 return(buf);
  35.             }
  36.         }
  37.         else
  38.         {
  39.             batchmode=0;
  40.             return buf;
  41.         }
  42.  
  43.     case 0:    return buf;
  44.  
  45.     case 1:    if (counter <= 0L)
  46.         {
  47.             while (strncmp(buf,"#! rnews ",9) &&
  48.                     strncmp(buf,"#!rnews ",8))
  49.             {
  50.                 loginf("batch out of sync: %s",buf);
  51.                 if (fgets(buf,count,fp) == NULL) return NULL;
  52.             }
  53.             sscanf(buf+8,"%ld",&counter);
  54.             debug(18,"next chunk of input batch: %ld",counter);
  55.             return NULL;
  56.         }
  57.         else
  58.         {
  59.             counter -= (long)strlen(buf);
  60.             debug(19,"bread \"%s\", %ld left of this chunk",
  61.                 buf,counter);
  62.             return buf;
  63.         }
  64.     }
  65.     return buf;
  66. }
  67.